/*
 * @Author: wuqingchun
 * @Date: 2024-04-25 13:57:01
 * @Description: 线程亲和性设置
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-04-25 14:02:55
 */
#ifndef __PERF_AFFINITY_H__
#define __PERF_AFFINITY_H__

#include <cstdint>

#include <pthread.h>

class PerfAffinity
{
public:
    static void SetThreadAffinity(uint32_t uiCpuId)
    {
        // 绑核
        cpu_set_t stCpuSet;
        CPU_ZERO(&stCpuSet);
        CPU_SET(uiCpuId, &stCpuSet);
        (void)pthread_setaffinity_np(pthread_self(), sizeof(stCpuSet), &stCpuSet);
    }
};

#endif //__PERF_AFFINITY_H__